<template>
  <div class="checkboxgroup">
    <label v-if="type === 1"
      ><van-checkbox v-model="isAd"
        ><slot name="checkboxgroupTitle">{{ title }}</slot></van-checkbox
      >
      <div class="checkboxgroup_content">
        <slot name="checkboxGroupContent" :isDisabled="!isAd"></slot></div
    ></label>
    <label v-if="type === 2" :class="type === 2 ? 'on' : ''"
      ><van-checkbox v-model="isAd"
        ><slot name="checkboxgroupTitle">{{ title }}</slot></van-checkbox
      >
      <div class="checkboxgroup_content">
        <slot name="checkboxGroupContent" :isDisabled="!isAd"></slot></div
    ></label>
  </div>
</template>
<script>
export default {
  name: "CheckboxGroup",
  props: {
    type: {
      type: Number,
      default() {
        return 1;
      },
    },
    checkValue: {
      type: Boolean,
      default() {
        return false;
      },
    },
    title: {
      type: String,
      default() {
        return "";
      },
    },
  },
  data() {
    return {
      isAd: false,
    };
  },
  created() {
    this.isAd = this.$props.checkValue;
  },
  watch: {
    isAd(v) {
      this.$emit("updateIsAd", v);
    },
  },
};
</script>
<style lang="less">
@base: 23.44rem;
.checkboxgroup {
  margin: 15 / @base 0;
  text-align: left;
  label {
    display: flex;
    margin: 20 / @base 0 0;
    width: 100%;
    &.on {
      display: block;
      .van-checkbox {
        width: auto;
      }
      .checkboxgroup_content {
        width: auto;
      }
    }
    .van-checkbox {
      width: 30%;
      align-items: flex-start;
      padding: 10 / @base 0 0;
    }
    .checkboxgroup_content {
      width: 80%;
    }
    span {
      display: block;
      text-align: right;
      font-size: 14 / @base;
    }
  }
}
</style>
